unit uFrmMain;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls, Buttons, uDZWinInetUtils, uDZStream;

type
  TFrmMain = class(TForm)
    lbledtUrl: TLabeledEdit;
    txtContent: TMemo;
    btnPost: TSpeedButton;
    btnGet: TSpeedButton;
    procedure btnPostClick(Sender: TObject);
    procedure btnGetClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  FrmMain: TFrmMain;

implementation

{$R *.dfm}

procedure TFrmMain.btnGetClick(Sender: TObject);
var
  HttpClient: TDzWinInetHttp;
begin
  HttpClient := TDzWinInetHttp.Create;
  try
    try
      txtContent.Lines.Add(HttpClient.Get(lbledtUrl.Text));
    except
      on E:Exception do
        txtContent.Lines.Add(E.ClassName + ': ' + E.Message);
    end;
  finally
    HttpClient.Free;
  end;
end;

procedure TFrmMain.btnPostClick(Sender: TObject);
var
  HttpClient: TDzWinInetHttp;
  Input, Output: TDzAnsiStrStream;
begin
  HttpClient := TDzWinInetHttp.Create;
  Input := TDzAnsiStrStream.Create(txtContent.Text);
  Output := TDzAnsiStrStream.Create('');
  HttpClient.PostContentType := 'application/x-www-form-urlencoded';
  try
    try
      HttpClient.Post(lbledtUrl.Text, Input, Output);
      txtContent.Lines.Add(Output.DataString);
    except
      on E:Exception do
        txtContent.Lines.Add(E.ClassName + ': ' + E.Message);
    end;
  finally
    HttpClient.Free;
    Input.Free;
    Output.Free;
  end;
end;

end.
